#ifndef TASK_BASED_THREAD_H_
#define TASK_BASED_THREAD_H_

#include "Thread.h"
class Scene;
class RayTracer;
class Camera;


class TaskBasedThread : public Thread
{
public:
    TaskBasedThread(Scene* s, RayTracer* rt, Camera* cam) :
    m_scene(s), m_rt(rt), m_cam(cam), m_shouldWait(false), m_numTasksCompleted(0)
    {
        m_threadID = -1;
        m_whichMask = 0;
        m_personalMask.SetAll(1,1,1,1);
        m_event = CreateEvent(0,0,0,0);
    }
    virtual void vRun(){vProcess();}
    virtual void vProcess();
    virtual void vPause()
    {
        m_shouldWait = true;

    }
    virtual void vStop()
    {
        m_tActive = false;
    }
    virtual void vResume()
    {
        m_shouldWait = false;
        SetEvent(m_event);
    }
    virtual bool vHasFinished()
    {
        return !m_tActive;
    }
    virtual int WaitForFinish()
    {
        m_tActive = false;
        m_shouldWait = false;
        vResume();
        return Thread::WaitForFinish();
    }       
    void AntiAlias();
    //0 for none, 1 for personal, 2 for task based
    void SetWhichMask(int x){m_whichMask = x;}
    void SetColor(Color& c){m_personalMask = c;}
    void SetID(int id){m_threadID = id;}

private:    
    RayTracer*  m_rt;
    Scene*      m_scene;
    Camera*     m_cam;
    HANDLE m_event;
    bool m_shouldWait;
    int m_numTasksCompleted;
    int m_whichMask;
    Color m_personalMask;
    int m_threadID;
};


#endif